import { getUserAddress, getUserOrderData } from "@/api"

export default {
  namespaced: true,
  state: {
    addressList: [
      {
        id: 1,
        name: "张三",
        phone: "15701180118",
        address: "北京市翻斗花园二单元15号楼8808",
        isChecked: false,
        default: true,
      },
      {
        id: 2,
        name: "李四",
        phone: "13838384389",
        address: "天津市宝宝花园三单元8号楼2117",
        isChecked: true,
        default: false,
      },
      {
        id: 3,
        name: "王五",
        phone: "18900010002",
        address: "北海道敬老院残疾关爱中心区六单元2号楼1006",
        isChecked: false,
        default: false,
      },
    ],
    userOrderList: {},
  },
  getters: {
    detailArrayList(state) {
      return state.userOrderList.detailArrayList
    },
    originalTotalAmount(state) {
      return state.userOrderList.originalTotalAmount
    },
    totalAmount(state) {
      return state.userOrderList.totalAmount
    },
    totalNum(state) {
      return state.userOrderList.totalNum
    },
    tradeNo(state) {
      return state.userOrderList.tradeNo
    },
  },
  actions: {
    async getUsers({ commit }) {
      const result = await getUserAddress()
      if (result.code === 200) {
        commit("USER_ADDRESS", result.data)
      } else {
        console.log(result.message)
      }
    },
    async getUserOrder({ commit }) {
      const result = await getUserOrderData()
      if (result.code === 200) {
        commit("GET_USER_ORDER", result.data)
      } else {
        console.log(result.message)
      }
    },
  },
  mutations: {
    USER_ADDRESS() {},
    GET_USER_ORDER(state, data) {
      state.userOrderList = data
    },
  },
}
